/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAL;

import java.sql.*;
public final class DBManager {
 
  private static DBManager _instance = null;
  private Connection _con = null;
 
  public DBManager() {
    //Connect to Ms Access
    _con = getSQLServerConnection();
  }
 
  //Thread safe instatiate method
  public static synchronized DBManager getInstance() {
    if (_instance == null) {
      _instance = new DBManager();
    }
    return _instance;
  }
 
  public Connection getConnection() {
    return _con;
  }
 
  /**
   * Connection to SQLServer Database
   */
  private static Connection getSQLServerConnection() {
    Connection con = null;
 
    try {
      Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
 
      String URL = "jdbc:sqlserver://localhost;databaseName=STK;user=sa;password=123456;";
      con = DriverManager.getConnection(URL);
    } catch (Exception e) {
      System.out.println(e);
    }
    return con;
  }
 
  /**
   * Connection to MySQL Database
   */
  private static Connection getMySQLConnection() {
    Connection con = null;
 
    try {
 
      String strCon = "jdbc:mysql://127.0.0.1/test?user=rtuser&password=123";
      con = DriverManager.getConnection(strCon);
    } catch (SQLException se) {
      System.out.println(se);
    }
    return con;
  }
 
  /**
   * Connection to Microsoft Access
   */
  private static Connection getMsAccessConnection() {
    Connection con = null;
    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      String filename = "Province.mdb";
      String URL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
      URL += filename + ";}";
 
      con = DriverManager.getConnection(URL);
 
    } catch (Exception se) {
      System.out.println(se);
    }
 
    return con;
  }
  public static void main(String[] str) throws SQLException
  {
  }
}